
const Mock = require('mockjs')
const { deepClone, getCommonRoutes } = require('@/utils/index')

const constantRoutes = [
  {
    path: '/redirect',
    component: 'layout/Layout',
    constant: true,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: 'views/redirect/index'
      }
    ]
  },
  {
    path: '/login',
    component: 'views/login/index',
    constant: true,
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: 'views/login/auth-redirect',
    constant: true,
    hidden: true
  },
  {
    path: '',
    component: 'layout/Layout',
    redirect: 'dashboard',
    key: 'A',
    children: [
      {
        path: 'dashboard',
        component: 'views/dashboard/index',
        name: 'Dashboard',
        key: 'A1',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
]

const asyncRoutes = [
  // {
  //   path: '/permission',
  //   component: 'layout/Layout',
  //   redirect: '/permission/index',
  //   alwaysShow: true,
  //   key: 'B',
  //   meta: {
  //     title: '权限管理',
  //     icon: 'lock',
  //     roles: ['admin', 'editor']
  //   },
  //   children: [
  //     {
  //       path: 'role',
  //       component: 'views/permission/role',
  //       name: 'RolePermission',
  //       key: 'B1',
  //       meta: {
  //         title: '权限管理',
  //         roles: ['admin']
  //       }
  //     }
  //   ]
  // },
  {
    path: '/usrgroup',
    key:'G',
    component: 'layout/Layout',
    redirect: '/usrgroup/list',
    name: 'Usrgroup',
    meta: {
      title: '用户组管理',
      icon: 'el-icon-s-order'
    },
    children: [
      {
        path: 'create',
        key:'G1',
        component: () => import('@/views/usrgroup/create'),
        name: 'CreateUsrgroup',
        meta: { title: '用户组新增', icon: 'edit' }
      },
      {
        path: 'edit/:id(\\d+)',
        key:'G2',
        component: () => import('@/views/usrgroup/edit'),
        name: 'EditUsrgroup',
        meta: { title: '用户组编辑', noCache: true, activeMenu: '/usrgroup/list' },
        hidden: true
      },
      {
        path: 'list',
        key:'G3',
        component: () => import('@/views/usrgroup/list'),
        name: 'UsrgroupList',
        meta: { title: '用户组清单', icon: 'list' }
      }
    ]
  },
  {
    path: '/usr',
    component: 'layout/Layout',
    redirect: '/usr/list',
    name: 'Usr',
    key: 'C',
    meta: {
      title: '用户管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
      {
        path: 'create',
        component: 'views/usr/create',
        key: 'C1',
        name: 'CreateUsr',
        meta: { title: '用户新增', roles: ['admin'] }
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/usr/edit',
        key: 'C2',
        name: 'EditUsr',
        meta: { title: '用户编辑', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/usr/list',
        key: 'C3',
        name: 'UsrList',
        meta: { title: '用户清单', icon: 'list' }
      }
    ]
  },

  {
    path: '/mpcp',
    key:'D',
    component: 'layout/Layout',
    redirect: '/mpcp/list',
    name: 'MPCP',
    meta: {
      title: 'LOT执行管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'create',
        key:'D1',
        component: () => import('@/views/mpcp/create'),
        name: 'CreateMPCP',
        meta: { title: 'LOT执行新增', icon: 'edit' },
        hidden: true
      },
      {
        path: 'edit/:id(\\d+)',
        key:'D2',
        component: () => import('@/views/mpcp/edit'),
        name: 'EditMPCP',
        meta: { title: 'LOT执行更新', noCache: true, activeMenu: '/mpcp/list' },
        hidden: true
      },
      {
        path: 'list',
        key:'D3',
        component: () => import('@/views/mpcp/list'),
        name: 'MPCPList',
        meta: { title: 'LOT执行清单', icon: 'list' }
      }
    ]
  },

  {
    path: '/mpcpend',
    key:'I',
    component: 'layout/Layout',
    redirect: '/mpcpend/list',
    name: 'MPCP',
    meta: {
      title: '生产/质量数据管理',
      icon: 'el-icon-s-help'
    },
    children: [
      {
        path: 'create',
        key:'I1',
        component: () => import('@/views/mpcpend/create'),
        name: 'CreateMPCP',
        meta: { title: '生产/质量数据新增', icon: 'edit' },
        hidden: true
      },
      {
        path: 'edit/:id(\\d+)',
        key:'I2',
        component: () => import('@/views/mpcpend/edit'),
        name: 'EditMPCP',
        meta: { title: '生产/质量数据更新', noCache: true, activeMenu: '/mpcpend/list' },
        hidden: true
      },
      {
        path: 'list',
        key:'I3',
        component: () => import('@/views/mpcpend/list'),
        name: 'MPCPList',
        meta: { title: '生产/质量数据清单', icon: 'list' }
      }
    ]
  },

  {
    path: '/boudf',
    key:'H',
    component: 'layout/Layout',
    redirect: '/boudf/list',
    name: 'BOUDF',
    meta: {
      title: 'LOT数据管理',
      icon: 'el-icon-s-marketing'
    },
    children: [
      {
        path: 'create',
        key:'H1',
        component: () => import('@/views/boudf/create'),
        name: 'CreateBOUDF',
        meta: { title: 'LOT数据新增', icon: 'edit' },
        hidden: true
      },
      {
        path: 'edit/:id(\\d+)',
        key:'H2',
        component: () => import('@/views/boudf/edit'),
        name: 'EditBOUDF',
        meta: { title: 'LOT数据更新', noCache: true, activeMenu: '/boudf/list' },
        hidden: true
      },
      {
        path: 'list',
        key:'H3',
        component: () => import('@/views/boudf/list'),
        name: 'BOUDFList',
        meta: { title: 'LOT数据履历', icon: 'list' }
      }
    ]
  },
  {
    path: '/res',
    component: 'layout/Layout',
    redirect: '/res/list',
    name: 'Res',
    key: 'E',
    meta: {
      title: '设备管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
      {
        path: 'create',
        component: 'views/res/create',
        key: 'E1',
        name: 'CreateRes',
        meta: { title: '设备新增', icon: 'edit', roles: ['admin'] }
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/res/edit',
        key: 'E2',
        name: 'EditRes',
        meta: { title: '设备编辑', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/res/list',
        key: 'E3',
        name: 'ResList',
        meta: { title: '设备清单', icon: 'list' }
      }
    ]
  },

  {
    path: '/edc',
    component: 'layout/Layout',
    redirect: '/edc/list',
    name: 'EDC',
    key: 'F',
    meta: {
      title: '参数管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
      {
        path: 'create',
        component: 'views/edc/create',
        key: 'F1',
        name: 'CreateEDC',
        meta: { title: '参数新增', icon: 'edit', roles: ['admin'] }
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/edc/edit',
        key: 'F2',
        name: 'EditEDC',
        meta: { title: '参数编辑', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/edc/list',
        key: 'F3',
        name: 'EDCList',
        meta: { title: '参数管理', icon: 'list' }
      }
    ]
  },

  {
    path: '/dropdown',
    component: 'layout/Layout',
    redirect: '/dropdown/list',
    name: 'Dropdown',
    key: 'J',
    meta: {
      title: '自定义参数管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
      {
        path: 'create',
        component: 'views/dropdown/create',
        key: 'J1',
        name: 'CreateDropdown',
        meta: { title: '参数新增', icon: 'edit', roles: ['admin'] },
        hidden: true
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/dropdown/edit',
        key: 'J2',
        name: 'EditDropdown',
        meta: { title: '参数编辑', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/dropdown/list',
        key: 'J3',
        name: 'DropdownList',
        meta: { title: '参数管理', icon: 'list' }
      }
    ]
  },

  {
    path: '',
    component: 'layout/Layout',
    redirect: 'dashboard',
    key: 'M',
    hidden: true,
    meta: {
      title: '班组管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
      {
        path: 'index/:hj',
        component: 'views/dashboard/index',
        key: 'M1',
        name: 'dashboard_hj',
        meta: { title: '混胶工程'},
        hidden: true
      },
      {
        path: 'index/:tb',
        component: 'views/dashboard/index',
        key: 'M2',
        name: 'dashboard_tb',
        meta: { title: '涂布工程'},
        hidde: true
      },
      {
        path: 'index/:fq',
        component: 'views/dashboard/index',
        key: 'M3',
        name: 'dashboard_fq',
        meta: { title: '熟化/分切工程'},
        hidden: true
      }
    ]
  },

  {
    path: '',
    component: 'layout/Layout',
    redirect: 'dashboard',
    key: 'N',
    hidden: true,
    meta: {
      title: '数据录入管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
      {
        path: 'index/:hj',
        component: 'views/dashboard/index',
        key: 'N1',
        name: 'dashboard_hj',
        meta: { title: '混胶工程生产数据'},
        hidden: true
      },
      {
        path: 'index/:tb',
        component: 'views/dashboard/index',
        key: 'N2',
        name: 'dashboard_tb',
        meta: { title: '涂布工程生产数据'},
        hidde: true
      },
      {
        path: 'index/:fq',
        component: 'views/dashboard/index',
        key: 'N3',
        name: 'dashboard_fq',
        meta: { title: '熟化/分切工程生产数据'},
        hidden: true
      },
      {
        path: 'index/:fq',
        component: 'views/dashboard/index',
        key: 'N4',
        name: 'dashboard_zl',
        meta: { title: '质量数据'},
        hidden: true
      }
    ]
  }
]

const cbr = [
  {
    path: '/redirect',
    component: 'layout/Layout',
    constant: true,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: 'views/redirect/index'
      }
    ]
  },
  {
    path: '/login',
    component: 'views/login/index',
    constant: true,
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: 'views/login/auth-redirect',
    constant: true,
    hidden: true
  }
]

const abr=[
  {
    path: '',
    component: 'layout/Layout',
    redirect: 'dashboard',
    key: 'A',
    children: [
    ]
  },
  {
    path: '/permission',
    component: 'layout/Layout',
    redirect: '/permission/index',
    alwaysShow: true,
    key: 'B',
    meta: {
      title: '权限管理',
      icon: 'lock',
      roles: ['admin', 'editor']
    },
    children: [
    ]
  },
  {
    path: '/usr',
    component: 'layout/Layout',
    redirect: '/usr/list',
    name: 'Usr',
    key: 'C',
    meta: {
      title: '用户管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
    ]
  },
  {
    path: '/mpcp',
    component: 'layout/Layout',
    redirect: '/mpcp/list',
    name: 'MPCP',
    key: 'D',
    meta: {
      title: 'LOT执行管理',
      icon: 'el-icon-s-order'
    },
    children: [
    ]
  },
  {
    path: '/usrgroup',
    key:'G',
    component: 'layout/Layout',
    redirect: '/usrgroup/list',
    name: 'Usrgroup',
    meta: {
      title: '用户组管理',
      icon: 'lock'
    },
    children: [
    ]
  },

  {
    path: '/boudf',
    key:'H',
    component: 'layout/Layout',
    redirect: '/boudf/list',
    name: 'BOUDF',
    meta: {
      title: 'LOT数据管理',
      icon: 'el-icon-s-marketing'
    },
    children: [
    ]
  },
  {
    path: '/res',
    component: 'layout/Layout',
    redirect: '/res/list',
    name: 'Res',
    key: 'E',
    meta: {
      title: '设备管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
    ]
  },

  {
    path: '/edc',
    component: 'layout/Layout',
    redirect: '/edc/list',
    name: 'EDC',
    key: 'F',
    meta: {
      title: '参数管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
    ]
  },

  {
    path: '/dropdown',
    component: 'layout/Layout',
    redirect: '/dropdown/list',
    name: 'Dropdown',
    key: 'J',
    meta: {
      title: '自定义参数管理',
      icon: 'course',
      roles: ['admin', 'editor']
    },
    children: [
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const acbr=[
    {
      path: 'dashboard',
      component: 'views/dashboard/index',
      name: 'Dashboard',
      key: 'A1',
      meta: { title: '首页', icon: 'dashboard', affix: true }
    },
    {
          path: 'role',
          component: 'views/permission/role',
          name: 'RolePermission',
          key: 'B1',
          meta: {
            title: '权限管理',
            roles: ['admin']
          }
        },
      {
        path: 'create',
        component: 'views/usr/create',
        key: 'C1',
        name: 'CreateUsr',
        meta: { title: '用户新增', roles: ['admin'] }
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/usr/edit',
        key: 'C2',
        name: 'EditUsr',
        meta: { title: '用户编辑', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/usr/list',
        key: 'C3',
        name: 'UsrList',
        meta: { title: '用户清单', icon: 'list' }
      },{
        path: 'create',
        component: 'views/mpcp/create',
        key: 'D1',
        name: 'CreateMPCP',
        meta: { title: 'LOT执行新增', icon: 'edit' }
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/mpcp/edit',
        key: 'D2',
        name: 'EditMPCP',
        meta: { title: 'LOT执行更新', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/mpcp/list',
        key: 'D3',
        name: 'MPCPList',
        meta: { title: 'LOT执行履历', icon: 'list' }
      },
      {
        path: 'create',
        key:'G1',
        component: '/views/usrgroup/create',
        name: 'CreateUsrgroup',
        meta: { title: '用户组新增', icon: 'edit' }
      },
      {
        path: 'edit/:id(\\d+)',
        key:'G2',
        component: '/views/usrgroup/edit',
        name: 'EditUsrgroup',
        meta: { title: '用户组编辑', noCache: true, activeMenu: '/usrgroup/list' },
        hidden: true
      },
      {
        path: 'list',
        key:'G3',
        component: '/views/usrgroup/list',
        name: 'UsrgroupList',
        meta: { title: '用户组清单', icon: 'list' }
      },
      {
        path: 'create',
        key:'H1',
        component: '/views/boudf/create',
        name: 'CreateBOUDF',
        meta: { title: 'LOT数据新增', icon: 'edit' },
        hidden: true
      },
      {
        path: 'edit/:id(\\d+)',
        key:'H2',
        component: '/views/boudf/edit',
        name: 'EditBOUDF',
        meta: { title: 'LOT数据更新', noCache: true, activeMenu: '/boudf/list' },
        hidden: true
      },
      {
        path: 'list',
        key:'H3',
        component: '/views/boudf/list',
        name: 'BOUDFList',
        meta: { title: 'LOT数据履历', icon: 'list' }
      },{
        path: 'create',
        component: 'views/res/create',
        key: 'E1',
        name: 'CreateRes',
        meta: { title: '设备新增', icon: 'edit', roles: ['admin'] }
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/res/edit',
        key: 'E2',
        name: 'EditRes',
        meta: { title: '设备编辑', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/res/list',
        key: 'E3',
        name: 'ResList',
        meta: { title: '设备清单', icon: 'list' }
      },{
        path: 'create',
        component: 'views/edc/create',
        key: 'F1',
        name: 'CreateEDC',
        meta: { title: '参数新增', icon: 'edit', roles: ['admin'] }
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/edc/edit',
        key: 'F2',
        name: 'EditEDC',
        meta: { title: '参数编辑', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/edc/list',
        key: 'F3',
        name: 'EDCList',
        meta: { title: '参数管理', icon: 'list' }
      },{
        path: 'create',
        component: 'views/dropdown/create',
        key: 'J1',
        name: 'CreateDropdown',
        meta: { title: '自定义参数新增', icon: 'edit', roles: ['admin'] },
        hidden: true
      },
      {
        path: 'edit/:id(\\d+)',
        component: 'views/dropdown/edit',
        key: 'J2',
        name: 'EditDropdown',
        meta: { title: '自定义参数编辑', noCache: true },
        hidden: true
      },
      {
        path: 'list',
        component: 'views/dropdown/list',
        key: 'J3',
        name: 'DropdownList',
        meta: { title: '自定义参数管理', icon: 'list' }
      }
]

const routes = deepClone([...constantRoutes, ...asyncRoutes])

const roles = [
  {
    key: 'admin',
    name: 'admin',
    description: '',
    routes: getCommonRoutes(cbr,abr,acbr,['A1','B1','C1','C2','C3','D1','D2','D3','E1','E2','E3','F1','F2','F3'])
  },
  {
    key: 'editor',
    name: 'editor',
    description: '',
    //routes: routes.filter(i => i.path !== '/permission'),
    routes: getCommonRoutes(cbr,abr,acbr,['A1','C1','C2','C3','E1','E2','E3','F1','F2','F3'])
  },
  {
    key: 'visitor',
    name: 'visitor',
    description: '',
    routes: getCommonRoutes(cbr,abr,acbr,['A1'])
    // routes: [{
    //   path: '',
    //   redirect: 'dashboard',
    //   children: [
    //     {
    //       path: 'dashboard',
    //       name: 'Dashboard',
    //       meta: { title: 'dashboard', icon: 'dashboard' }
    //     }
    //   ]
    // }],
  }
]

export function getRoutes() {
  return new Promise((resolve,reject)=>{
    resolve({
        code: 20000,
        data: routes
      })
  })
}

export function getRoles() {
  return new Promise((resolve,reject)=>{
    resolve({
        code: 20000,
        data: roles
      })
  })
}

export function addRole(data) {
  return new Promise((resolve,reject)=>{
    resolve({
      code: 20000,
      data: {
        Code: Mock.mock('@integer(300, 5000)')
      }
    })
  })
}

export function updateRole(id, data) {
  return new Promise((resolve,reject)=>{
    resolve({
      code: 20000,
      data: {
        status: 'success'
      }
    })
  })
}

export function deleteRole(id) {
  return new Promise((resolve,reject)=>{
    resolve({
      code: 20000,
      data: {
        status: 'success'
      }
    })
  })
}
